<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper search-box-cuesList">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="6" :md="6" :sm="24">
            <a-form-item>
              <a-select v-model="queryParam.platformType" placeholder="请选择" default-value="0" class="select-box">
                <a-select-option value="1">微信</a-select-option>
                <a-select-option value="2">抖音</a-select-option>
                <a-select-option value="3">头条</a-select-option>
                <a-select-option value="4">微博</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="8" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search" title="搜索" shape="circle"></a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
                title="重置"
                shape="circle"></a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="display:flex;padding-left: 10px; align-items: center;">
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="flex:1;text-align: left;margin-bottom:0">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <!-- <a-button type="primary" icon="download" @click="handleExportXls('第三方平台信息')">导出</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
              <a-button type="primary" icon="import">导入</a-button>
            </a-upload> -->
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
          </a-dropdown>
        </div>
        <div>
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>
      </div>

      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" title="编辑"><a-icon type="edit" theme="filled"/></a>

          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a title="删除"><a-icon type="delete" theme="filled" style="color:#ed7770"/></a>
          </a-popconfirm>

<!--          <a-divider type="vertical" />-->
<!--          <a title="授权"><a-icon type="security-scan" theme="filled"/></a>-->
          <!--
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item @click="authorize(record)">
                  <a title="授权"><a-icon type="security-scan" theme="filled"/></a>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <basThirdInfo-modal ref="modalForm" @ok="modalFormOk"></basThirdInfo-modal>
  </a-card>
</template>

<script>
import BasThirdInfoModal from './modules/BasThirdInfoModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'

export default {
    name: 'BasThirdInfoList',
    mixins: [JeecgListMixin],
    components: {
        BasThirdInfoModal
    },
    data () {
        return {
            description: '第三方平台信息管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: 'center',
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1
                    }
                },
                {
                    title: '自媒体类型',
                    align: 'center',
                    dataIndex: 'platformTypeName'
                },
                {
                    title: '平台注册名称',
                    align: 'center',
                    dataIndex: 'platformName'
                },
                {
                    title: '应用唯一标识',
                    align: 'center',
                    dataIndex: 'clientKey'
                },
                {
                    title: '应用唯一标识对应的密钥',
                    align: 'center',
                    dataIndex: 'clientSecret'
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: 'center',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            url: {
                list: '/base/basThirdInfo/list',
                delete: '/base/basThirdInfo/delete',
                deleteBatch: '/base/basThirdInfo/deleteBatch',
                exportXlsUrl: 'base/basThirdInfo/exportXls',
                importExcelUrl: 'base/basThirdInfo/importExcel'
            }
        }
    },
    mounted () {
        console.log(this.$route.query)
        if (this.$route.query.state && this.$route.query.code) {
            getAction('/base/basThirdInfo/finishAuthorize', {
                code: this.$route.query.code,
                id: this.$route.query.state
            }).then((res) => {
            })
        }
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
        }
    },
    watch: {
        dataSource (newValue, oldValue) {
            for (let item of newValue) {
                switch (item.platformType) {
                case 1:
                    item.platformTypeName = '微信'
                    break
                case 2:
                    item.platformTypeName = '抖音'
                    break
                case 3:
                    item.platformTypeName = '头条'
                    break
                case 4:
                    item.platformTypeName = '微博'
                    break
                default:
                    break
                }
            }
        }
    },
    methods: {
        authorize (record) {
            location.href = 'https://api.weibo.com/oauth2/authorize?client_id=' + record.clientKey + '&redirect_uri=http://106.12.9.35/media-view-boss/base/thirdInfo&response_type=code&display=default&state=' + record.id
        }
    }
}
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
